package com.zhengdongzulin.zuke.app.main.mine.lifeservice

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.app.data.LifeService
import com.zhengdongzulin.zuke.base.BaseViewModel
import com.zhengdongzulin.zuke.parser.ObjectList
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class LifeServiceVm : BaseViewModel() {

    //保洁列表
    var clean_list: StateLiveData<ObjectList<LifeService>> = StateLiveData()
    fun clean_list(houseId: String, status: String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.CLEAN_LIST)
                            .add("houseId", houseId)
                            .add("status", status)
                            .add("renterPhone", mShareViewModel!!.userInfo.value!!.phone)
                            .add("current", mCurrentPage)
                            .add("size", mPageSize)
                            .toResponse<ObjectList<LifeService>>()
                            .await()
                    clean_list.postValueAndSuccess(r)
                }, {
            assignment(it, clean_list)
        }
        )
    }


    //维修列表
    var repair_list: StateLiveData<ObjectList<LifeService>> = StateLiveData()
    fun repair_list(houseId: String, status: String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.REPAIR_LIST)
                            .add("houseId", houseId)
                            .add("status", status)
                            .add("renterPhone", mShareViewModel!!.userInfo.value!!.phone)
                            .add("current", mCurrentPage)
                            .add("size", mPageSize)
                            .toResponse<ObjectList<LifeService>>()
                            .await()
                    repair_list.postValueAndSuccess(r)
                }, {
            assignment(it, repair_list)
        }
        )
    }

    //投诉列表
    var complaint_letter_list: StateLiveData<ObjectList<LifeService>> = StateLiveData()
    fun complaint_letter_list(houseId: String, status: String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.COMPLAINT_LETTER_LIST)
                            .add("houseId", houseId)
                            .add("status", status)
                            .add("renterPhone", mShareViewModel!!.userInfo.value!!.phone)
                            .add("current", mCurrentPage)
                            .add("size", mPageSize)
                            .toResponse<ObjectList<LifeService>>()
                            .await()
                    complaint_letter_list.postValueAndSuccess(r)
                }, {
            assignment(it, complaint_letter_list)
        }
        )
    }

    //取消保洁
    var clean_cancel: StateLiveData<String> = StateLiveData()
    fun clean_cancel(id: String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.CLEAN_CANCEL)
                            .add("id", id)
                            .toResponse<String>()
                            .await()
                    clean_cancel.postValueAndSuccess(r)
                }, {
            assignment(it, clean_cancel)
        }
        )
    }

    //取消维修
    var repair_cancel: StateLiveData<String> = StateLiveData()
    fun repair_cancel(id: String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.REPAIR_CANCEL)
                            .add("id", id)
                            .toResponse<String>()
                            .await()
                    repair_cancel.postValueAndSuccess(r)
                }, {
            assignment(it, repair_cancel)
        }
        )
    }

    //取消投诉
    var complaint_letter_cancel: StateLiveData<String> = StateLiveData()
    fun complaint_letter_cancel(id: String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.COMPLAINT_LETTER_CANCEL)
                            .add("id", id)
                            .toResponse<String>()
                            .await()
                    complaint_letter_cancel.postValueAndSuccess(r)
                }, {
            assignment(it, complaint_letter_cancel)
        }
        )
    }


    //保洁评价
    var clean_appraise: StateLiveData<String> = StateLiveData()
    fun clean_appraise(id: String, grade: String, gradeContent: String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.CLEAN_APPRAISE)
                            .add("id", id)
                            .add("grade", grade)
                            .add("gradeContent", gradeContent)
                            .toResponse<String>()
                            .await()
                    clean_appraise.postValueAndSuccess(r)
                }, {
            assignment(it, clean_appraise)
        }
        )
    }

    //维修评价
    var repair_appraise: StateLiveData<String> = StateLiveData()
    fun repair_appraise(id: String, grade: String, gradeContent: String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.REPAIR_APPRAISE)
                            .add("id", id)
                        .add("grade", grade)
                        .add("gradeContent", gradeContent)
                            .toResponse<String>()
                            .await()
                    repair_appraise.postValueAndSuccess(r)
                }, {
            assignment(it, repair_appraise)
        }
        )
    }

    //投诉评价
    var complaint_letter_appraise: StateLiveData<String> = StateLiveData()
    fun complaint_letter_appraise(id: String, grade: String, gradeContent: String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.COMPLAINT_LETTER_APPRAISE)
                            .add("id", id)
                        .add("grade", grade)
                        .add("gradeContent", gradeContent)
                            .toResponse<String>()
                            .await()
                    complaint_letter_appraise.postValueAndSuccess(r)
                }, {
            assignment(it, complaint_letter_appraise)
        }
        )
    }


}